package com.neusoft.elm.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.neusoft.elm.po.User;
import com.neusoft.elm.service.UserService;
import com.neusoft.elm.service.impl.UserServiceImpl;

import javax.servlet.http.HttpServletRequest;

public class UserController {
    UserService userService = new UserServiceImpl();

    //注册
    public Object saveUser(HttpServletRequest request) throws Exception{
        String userId = request.getParameter("userId");
        String password = request.getParameter("password");
        String userName = request.getParameter("userName");
        Integer userSex = Integer.valueOf(request.getParameter("userSex"));
        String userImg = request.getParameter("userImg");
        User user = new User(userId,password,userName,userSex,userImg,null);
        int n = userService.saveUser(user);
        return n;
    }
    //登陆
    public Object getUserByIdByPass(HttpServletRequest request) throws Exception{
        String userId = request.getParameter("userId");
        String password = request.getParameter("password");
        User user = userService.getUserByIdByPass(userId, password);
        return user;
    }

    //检查手机号码是否可用
    public Object getUserById(HttpServletRequest request) throws Exception{
        String userId = request.getParameter("userId");
        User user = userService.getUserById(userId);
        return user;
    }
}
